<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>SQL转Java JPA、MYBATIS实现类代码生成平台</title>
    <meta name="keywords" content="sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现">
    <#import "common/common-import.html" as netCommon>
    <@netCommon.commonStyle />
    <@netCommon.commonScript />
    <#--
    <script src="${request.contextPath}/static/js/index-new.js"></script>
    -->

</head>
<body style="background-color: #e9ecef">
<div>
    <div class="container">
        <h2>Spring Boot Code Generator!</h2>
        <hr>
        <p>
            <code>使用方式一：</code>配置数据库，直接选择数据表，生成表对应的对象
            <br>
            <code>使用方式二：</code>直接在页面，粘贴建表SQL.(优先方式一，如果要用方式二，请把表名重置为： ---请选择---)
        </p>
        <div class="input-group mb-4">
            <div class="input-group-prepend">
                <span class="input-group-text">表名</span>
            </div>
            <select id="tableName" name="tableName" class="form-control">
                <option value="">---请选择---</option>
                <#list tables as table>
                    <option value="${table}">${table}</option>
                </#list>
            </select>

            <span class="input-group-text">表名前缀</span>
            <select id="tableNamePre" name="tableNamePre" class="form-control">
                <option value="">---请选择---</option>
                <#list tableNamePre as pre>
                    <option value="${pre}">${pre}</option>
                </#list>
            </select>
            <div class="input-group-prepend">
                <span class="input-group-text">作者名称</span>
            </div>
            <input type="text" class="form-control" id="authorName" name="authorName" placeholder="${author}" value="${author} ">

            <span class="input-group-text">包名路径</span>
            <input type="text" class="form-control" id="packageName" name="packageName" placeholder="${package}" value="${package}">

        </div>
        <textarea id="ddlSqlArea" placeholder="请输入表结构信息..." class="btn-md">${ddlSQL}</textarea>
        <br>
        <p>
            <button class="btn btn-primary btn-md disabled" id="btnGenCode" role="button">开始生成 »</button>
        </p>

        <hr>
        <!-- Example row of columns -->
        <div class="row" style="margin-top: 10px;">
            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " >通用实体</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="model">entity(set/get)</button>
                    <button type="button" class="btn btn-default generator" id="beetlentity">entity(lombok)</button>
                </div>
            </div>
            <div class="btn-toolbar col-md-7" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " >Mybatis</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="mybatis">mybatis</button>
                    <button type="button" class="btn btn-default generator" id="mapper">mapper</button>
                    <button type="button" class="btn btn-default generator" id="service">service</button>
                    <button type="button" class="btn btn-default generator" id="service_impl">service_impl</button>
                    <button type="button" class="btn btn-default generator" id="controller">controller</button>
                </div>
            </div>
        </div>
        <!-- Example row of columns -->
        <div class="row" style="margin-top: 10px;">
            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " >MybatisPlus</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="plusmapper">mapper</button>
                    <button type="button" class="btn btn-default generator" id="pluscontroller">controller</button>
                </div>
            </div>

            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " >UI</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="swagger-ui">swagger-ui</button>
                    <button type="button" class="btn btn-default generator" id="element-ui">element-ui</button>
                    <button type="button" class="btn btn-default generator" id="bootstrap-ui">bootstrap-ui</button>
                </div>
            </div>
        </div>

        <div class="row" style="margin-top: 10px;">
            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " >BeetlSQL</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="beetlmd">beetlmd</button>
                    <button type="button" class="btn btn-default generator" id="beetlcontroller">beetlcontroller
                    </button>
                </div>
            </div>
            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " onclick="sendCreateFiles('entity,repository,jpacontroller')" >JPA</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="entity">jpa-entity</button>
                    <button type="button" class="btn btn-default generator" id="repository">repository</button>
                    <button type="button" class="btn btn-default generator" id="jpacontroller">controller</button>
                </div>
            </div>
        </div>
        <div class="row" style="margin-top: 10px;">
            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " >JdbcTemplate</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="jtdaoimpl">daoimpl</button>
                    <button type="button" class="btn btn-default generator" id="jtdao">dao</button>
                </div>
            </div>

            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " >DTO</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="beetlentitydto">
                        entitydto(lombok+swagger)
                    </button>
                </div>
            </div>
        </div>
		<div class="row" style="margin-top: 10px;">
            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " >ant-design</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="base-list">base-list</button>
                    <button type="button" class="btn btn-default generator" id="service-api">service-api</button>
                    <button type="button" class="btn btn-default generator" id="models">models</button>
                </div>
            </div>
            <div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="btn btn-secondary " onclick="sendCreateFiles('mongo_document,mongo_reposititory,mongo_controller')" >Mongo-Reactive</div>
                    </div>
                </div>
                <div class="btn-group" role="group" aria-label="First group">
                    <button type="button" class="btn btn-default generator" id="mongo_document">mongo-entity</button>
                    <button type="button" class="btn btn-default generator" id="mongo_reposititory">mongo-repository</button>
                    <button type="button" class="btn btn-default generator" id="mongo_controller">mongo-controller</button>
                </div>
            </div>
        </div>
        <hr>
    </div>
</div>
<script>
    $(function () {

        /**
         * 初始化 table sql 3
         */
        var ddlSqlArea = CodeMirror.fromTextArea(document.getElementById("ddlSqlArea"), {
            lineNumbers: true,
            matchBrackets: true,
            mode: "text/x-sql",
            lineWrapping:false,
            readOnly:false,
            foldGutter: true,
            gutters:["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
        });

        /**
         * 生成代码
         */
        var codeData;
        $('#btnGenCode').click(function ()  {
            var tableSql = ddlSqlArea.getValue();
            $.ajax({
                type: 'POST',
                url: base_url + "/genCode",
                data: {
                    "tableSql": tableSql,
                    "packageName":$("#packageName").val(),
                    "tableName":$("#tableName").val(),
                    "authorName":$("#authorName").val(),
                    "tableNamePre":$("#tableNamePre").val()
                },
                dataType: "json",
                success: function (data) {
                   layer.msg('代码生成成功', {time:2000});
                   codeData = data;
                }
            });
        });

        /**
         * 查看类代码
         */
        $('.generator').bind('click', function () {
            if (!$.isEmptyObject(codeData)) {
                var id = this.id;
                var index = layer.open({
                  type: 2,
                  content: "/showCode?code="+id,
                  area: ['320px', '195px'],
                  maxmin: true
                });
                layer.full(index);
            }
        });

    });

    function sendCreateFiles(codeStr){
        $.ajax({
            type: 'POST',
            url: "/createFiles",
            data: {
                "codeStr": codeStr,
            },
            dataType: "json",
            success: function (data) {
               layer.msg('代码生成成功', {time:2000});
            }
        });
    }
    </script>
</body>
</html>
